package org.zhenhu.CSCE310.KnapSack;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ReadFile {
	
	public static void readFile(String fileName){
		Scanner read = null;
		
		try{
			read = new Scanner(new File(fileName));
		} catch(FileNotFoundException e){
			e.printStackTrace();
		}
		
		String firstLine = read.nextLine();
		String[] firstLineToken = firstLine.split(" ");
		int size = Integer.parseInt(firstLineToken[0]);
		double maxWeight = Double.parseDouble(firstLineToken[1]);
	
		String line;
		String[] lineToken;
		
		List<Double> list_weight = new ArrayList<Double>();
		List<Double> list_value = new ArrayList<Double>();
		while(read.hasNextLine()){
			line = read.nextLine();
			lineToken = line.split(" ");
			for(int i = 0; i < size; i++){
				if(list_weight.size()==size){
				list_value.add(Double.parseDouble(lineToken[i]));
				}else{
					list_weight.add(Double.parseDouble(lineToken[i]));
				}
				
			}
		}
		
//		System.out.println(list_value);
//		System.out.println(list_weight);
		KnapSack test = new KnapSack();
//		test.knapSack(list_value, list_weight, maxWeight);
		
		List<Integer> print = test.getIndex(test.knapSack(list_value, list_weight, maxWeight), list_value);
		
		if(print == null){
			System.out.println("No optimal knapsack solution");
		}
		else{
			System.out.println("Optimal knapsack: "+print);
		}
		read.close();
	}




}
